﻿
Imports System.IO
Imports std

Public Class merger
    Inherits loghandler

    Public Shadows Const backupConfignaming As String = "merger"
    Public Const mergerFileSuffix As String = ".merger.log"
    Protected writer As StreamWriter = Nothing
    Protected writetally As tally = Nothing

    Public Sub New()
        caseConfigNaming = configNaming.merger.merger
        multimatch = configNaming.defaultValue.merger.multimatch
        MyBase.backupConfignaming = backupConfignaming
    End Sub

    Protected Overrides Sub initial()
        Dim logfile As String = Nothing
        logfile = defaultOutputfile(configNaming.defaultValue.merger.outputpath) + mergerFileSuffix
        If Not createWriter(writer, logfile) Then
            raiseError("cannot create writer for file " + logfile + ", cannot handle request." _
                       , errorHandle.errorType.system)
        End If
        writetally = New tally(configParameter(configNaming.counter.flushtimes _
                                               , configNaming.defaultValue.merger.flushtimes))
    End Sub

    Protected Overrides Sub oneline(ByRef log As String, ByRef casename As String)
        If Not writer Is Nothing Then
            writer.WriteLine(casename + errorHandle.seperator + log)
            If writetally.tick() Then
                writer.Flush()
                writer.BaseStream.Flush()
            End If
        End If
    End Sub
End Class
